package com.org.controller;

import com.org.constant.ResponseEnum;
import com.org.exception.RespException;
import com.org.form.AgreementInfoForm;
import com.org.model.AgreementDetail;
import com.org.service.AgreementDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * author: vane.Q
 * date: 2022/10/19 14:53
 */
@RestController
@RequestMapping("/sys")
public class AgreementInfoController {

    @Autowired
    private AgreementDetailService agreementDetailService;

    /**
     * 获取协议
     *
     * @param
     * @return
     */
    @GetMapping(value = {"/getAgreement/{agreementNo}", "/getAgreement/{agreementNo}/{version}"})
    public ModelAndView getAgreement(@PathVariable String agreementNo,
                                     @PathVariable(required = false) Integer version) {
//        PrintWriter out = response.getWriter();
//        try {
//            String file = agreementDetailService.getAgreement(agreementNo, version);
//            response.setContentType("text/html");
//            out.println("<html><body>" + file + "</body></html>");
//        } catch (Exception ex) {
//            throw new RespException(ResponseEnum.ERR_CTL_FILE_PREVIEW_FAIL);
//        } finally {
//            out.close();
//        }

        return agreementDetailService.getAgreement(agreementNo, version);

    }

    @PostMapping("/getAgreementInfo")
    public void getAgreementInfo(@Validated(value = AgreementInfoForm.QueryAgreement.class) AgreementInfoForm form) throws IOException {

    }

}
